<!--收入审核--车站票款差异-->
<template>
  <div class="shouPiaoYuanPKCYDXC el-card is-always-shadow el-card__body">
    <avue-crud
      ref="crud"
      :option="option"
      :table-loading="listLoading"
      :data="data"
      :search.sync="searchForm"
      :page.sync="page"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @refresh-change="refreshChange"
      @on-load="getList">
      <template slot="menuRight">
        <el-button type="primary"  size="mini" @click="addOrEditor(null,2)">添加</el-button>
        <!--<el-button type="primary"  size="mini" @click="chezhanJieSuan()">车站结算</el-button>-->
        <el-button type="primary"  size="mini" @click="notice">通知</el-button>
	<el-button type="primary" size="mini" @click="handleDelete">删除</el-button>
        <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
      </template>
      <template slot-scope="scope" slot="lineCodeSearch">
        <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
          <el-option
            v-for="(item,index) in lineCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="stationCodeSearch">
        <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable filterable>
          <el-option
            v-for="(item,index) in stationCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <!-- <template slot-scope="scope" slot="diffAmountSearch" style="width: 500px;">
        <div style="width: 500px;">
          <el-form-item>
            <el-input-number v-model="searchForm.minDiffAmount" controls-position="right" ></el-input-number>~
            <el-input-number v-model="searchForm.maxDiffAmount" controls-position="right"  ></el-input-number>
          </el-form-item>
        </div>
      </template> -->
      <template slot="search" slot-scope="{row,size}">
          <el-form-item label="收入日期" style="width: 560px">
              <div style="width: 400px;display: inline-flex">
                <el-date-picker
                  v-model="searchForm.startIncomeTime"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd">
                </el-date-picker>
                ~
                <el-date-picker
                  v-model="searchForm.endIncomeTime"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd">
                </el-date-picker>
              </div>
          </el-form-item>
	  <el-form-item label="差异条件" style="width: 300px" >
            <el-select v-model="searchForm.isDifferenceAmount" placeholder="请选择" clearable>
              <el-option label="长款" value="1"></el-option>
              <el-option label="短款" value="2"></el-option>
            </el-select>
          </el-form-item>
      </template>
      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" v-if="/*scope.row.settleStatus=='0' || */scope.row.isAddNotice != 1" size="small" plain @click.stop="addOrEditor(scope.row,1)">编辑</el-button>
        <el-button type="text" size="small" plain @click.stop="addOrEditor(scope.row,3)">预览</el-button>
      </template>
    </avue-crud>
    <Add ref="Add" v-if="isShowDiaAdd"></Add>
</div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import moment from "moment";
    import {
      chezhan_IS_ADD_NOTICE,
      clearSelect,
      fenExYuangettoFixed, getChezhan_IS_ADD_NOTICE, getChezhan_settle_status,
      getgetStationCodes,
      getLineCodes, getLineName, getStationName,
      getXieChaStatusFormat, setSearchFiledsEmpty,
      xieChaStatus, is_sup_payment, getIs_sup_payment
    } from "../../../../../api/subwayRat/commonCheck";
    import {exportDataToExcel} from "../../../../../api/subwayRat/exportSelf";
    import {
      chezhanJieSuanSwAuStationTicketDifference,
      getSwAuStationTicketDifferenceList,
      delObj,
      noticeSwAuStationTicketDifference
    } from "../../../../../api/subwayRat/conductorDifferences/conductorTicketChaYiShenhe/cheZhanPKCY/cheZhanPKCY";
    import Add from "./Add";
   export default {
      components:{
        Add
      },
      data() {
            return {
              isShowDiaAdd:false, //添加页面
              listLoading: true,
              lineCodes:[],
              stationCodes:[],
              tvmCodes:[],
              selectKeys:[], //存放对像
              selectKeyVals:[], //存放值
              data: [],
              searchForm:{
                lineCode:'',
                stationCode:'',
                isAddNotice: '0'
              },
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              option:{ },
            }
        },
        created() {
        this.getOption();
        },
        methods: {
          setSearchFiledsEmpty,
          refreshChange() {
            this.getList()
          },
          getList() {
            this.listLoading = true;
            Object.assign(this.searchForm,this.page);
            let param={compareType:4};
            Object.assign(param,this.searchForm);
            if(/\d+/g.test(param.minDiffAmount) && /\d+/g.test(param.maxDiffAmount)){
              param.minDiffAmount=param.minDiffAmount*100;
              param.maxDiffAmount=param.maxDiffAmount*100;
            }else{
              param.minDiffAmount='';
              param.maxDiffAmount='';
            }

            getSwAuStationTicketDifferenceList(param).then((response)=>{
              this.data = response.data.data;
              this.listLoading = false;
              this.page.total=response.data.total;
            });
          },
          selectionChange(list){
            this.selectKeys=list;
            this.selectKeyVals=[];
            for(let i=0;i<list.length;i++){
              this.selectKeyVals.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.getList();
            done()
          },
          notice(){
            if(this.selectKeys.length<=0){
              this.$message.warning("请选择加入通知的数据！");
              return;
            }

            for(let i=0;i<this.selectKeys.length;i++){
              if(this.selectKeys[i].isAddNotice==1){
                this.$message.warning("请选择未加入通知的数据！");
                return;
              }
            }

            noticeSwAuStationTicketDifference({ids:this.selectKeyVals.join(",")}).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.getList();
              }else{
                this.$message.error(res.data.msg);
              }
            })
          },
          previewEditor(row){ //回馈预览
            this.isShowDia=true;
            this.$nextTick(()=>{
              this.$refs.Editor.recallShow(row);
            })
          },
          addOrEditor(row,showType){
            this.isShowDiaAdd=true;
            this.$nextTick(()=>{
              this.$refs.Add.recallShow(row,showType);
            })
          },
          chezhanJieSuan(){ //车站结算
            if(this.selectKeys.length<=0){
              this.$message.warning("请选择结算数据！");
              return;
            }
            for(let i=0;i<this.selectKeys.length;i++){
              if(this.selectKeys[i].settleStatus==1){
                this.$message.warning("请选择未结算数据！");
                return;
              }
            }

            chezhanJieSuanSwAuStationTicketDifference({ids:this.selectKeyVals.join(',')}).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.getList();
              }else{
                this.$message.error(res.data.msg);
              }
            })
          },
	   //删除
        handleDelete: function () {
		if(this.selectKeys.length<=0){
		  this.$message.error('请选择要删除的数据！');
		  return;
		}
		 for(let i=0;i<this.selectKeys.length;i++){
		  if(this.selectKeys[i].auditState==1){
		    this.$message.warning("请选择未加入通知的数据！");
		    return;
		  }
		}
		this.$confirm("是否需要删除?", "提示", {
		  confirmButtonText: "确定",
		  cancelButtonText: "取消",
		  type: "success"
		}).then(() => {
		  delObj({ids: this.selectKeyVals})
		    .then(data => {
		      if (data.data.code == "0") {
			this.$message.success("删除成功");
		      }
		      this.getList(this.page);
		      done();
		    })
		    .catch(() => {
		      loading();
		    });
		});		
         },
          changeLine(v){ //改变线路时
            getgetStationCodes(v).then(res=>{
              this.stationCodes=res;
              this.searchForm.stationCode='';
            });
          },
          isassistInvestStatus(){ // 是否协查
            for(let i=0;i<this.selectKeys.length;i++){
              let row=this.selectKeys[i];
              if(row.assistStatus==3){
                return false
              }
            }
            return true;
          },
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
                let newData = JSON.parse(JSON.stringify(this.selectKeys));
                exportDataToExcel(newData,this.option.column,'车站票款差异');
            }else {
              let res=await getSwAuStationTicketDifferenceList(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'车站票款差异');
            }
          },
          getOption(){
            let th=this;
            this.option={
              emptyBtn:false,
              editBtn:false,
              delBtn:false,
              addBtn:false,
              border: true,
              index:true,
              indexLabel:'序号',
              page:true,
              align:'center',
              menuWidth:150,
              menuAlign:'center',
              selection: true,
              reserveSelection:false,
              column:[{label:"线路",width:100,
                "prop":"lineCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
              return getLineName(value);
            }},
                {label:"站点",width:180,
                  "prop":"stationCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
              return getStationName(row.lineCode,value);
            }},
                {label:"车站人员",width:120,
                  "prop":"conductorPersonName"},
                {label:"员工号",width:120,
                  "prop":"conductorJobNo"},
                {label:"收入日期",width:120,
                  "prop":"incomeTime",type:'date',valueFormat:'yyyy-MM-dd',search:false},
                {label:"结算开始日期",width:120, 
                  "prop":"settleBeginDate",type:'date'},
                {label:"结算结束日期",width:120, type:'date', "prop":"settleEndDate"},
                {label:"营收总金额",width:120, 
                  "prop":"cashReceiptsAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'cashReceiptsAmount');
                  }},
                {label:"补款金额",width:120, 
                  "prop":"shortAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'shortAmount');
                  }},
                {label:"现金缴款单金额",width:140, 
                  "prop":"cashPayAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'cashPayAmount');
                  }},
                {label:"差异金额", "prop":"diffAmount",
                //search:true,searchslot:true,
                formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'diffAmount');
                  }},
                // {label:"结算状态", "prop":"settleStatus",type:'select',formatter:function (row,v) {
                //       return getChezhan_settle_status(v);
                //   }},
                {label: "补款状态", prop: "suappStatus",type:'select',search:true,dicData:is_sup_payment(),formatter:function (row,v) {
                  return getIs_sup_payment(v);
                }},
                {label:"通知状态",
                  "prop":"isAddNotice",type:'select',searchValue:'0',search:true,dicData:chezhan_IS_ADD_NOTICE(),
                  formatter:function(row, value , label, column){
                    return getChezhan_IS_ADD_NOTICE(value);
                  }},
              ]
            }
          },
          getChaYi(row,compareFirst,compareSec){ //结账金额 sc 差额
            if(!row[compareFirst] || !row[compareSec]){
              return '';
            }
            return Number(row[compareFirst])-Number(row[compareSec]);
          }
        },
      mounted() {
        getLineCodes().then(res=>{ //获取线路
          this.lineCodes=res;
        });
      }
    }
</script>
<style lang="scss">

</style>
